Conversation
Contributor
Author
|
@lndgalante I requested your review. |
lndgalante
reviewed
Jun 4, 2020
Comment on lines
+58
to
+71
| let contractMethod = contractABI.find((method) => methodName === method.name); | ||
|
|
||
| //If we are over loaded, check how many inputs this method has. | ||
| if (contractMethods.length > 1) { | ||
| //Get all the inputs for the Method. | ||
| const contractInputs = Array.from( | ||
| document.querySelectorAll(createAttributeSelector(`data-dh-property-method-id`, methodId)), | ||
| ).filter((element) => !(element.getAttribute('id') || '').includes('dh')).filter((element) => element.nodeName === 'INPUT') | ||
|
|
||
| //Get the method that has the number of imputs which matches | ||
| contractMethod = contractMethods.filter((method) => method.inputs.length === contractInputs.length)[0] | ||
|
|
||
| //If the number of inputs does not match either function, then it's an error. | ||
| } |
Contributor
There was a problem hiding this comment.
Would prefer const and use of destructuring for avoiding variable mutations and code simplicity
Code example:
Suggested change
| let contractMethod = contractABI.find((method) => methodName === method.name); | |
| //If we are over loaded, check how many inputs this method has. | |
| if (contractMethods.length > 1) { | |
| //Get all the inputs for the Method. | |
| const contractInputs = Array.from( | |
| document.querySelectorAll(createAttributeSelector(`data-dh-property-method-id`, methodId)), | |
| ).filter((element) => !(element.getAttribute('id') || '').includes('dh')).filter((element) => element.nodeName === 'INPUT') | |
| //Get the method that has the number of imputs which matches | |
| contractMethod = contractMethods.filter((method) => method.inputs.length === contractInputs.length)[0] | |
| //If the number of inputs does not match either function, then it's an error. | |
| } | |
| //Get all the inputs for the Method. | |
| const contractInputs = Array.from( | |
| document.querySelectorAll(createAttributeSelector(`data-dh-property-method-id`, methodId)), | |
| ) | |
| .filter((element) => !(element.getAttribute('id') || '').includes('dh')) | |
| .filter((element) => element.nodeName === 'INPUT'); | |
| // If we are over loaded, check how many inputs this method has. | |
| const contractMethod = | |
| contractMethods.length > 1 | |
| ? contractMethods.filter((method) => method.inputs.length === contractInputs.length)[0] | |
| : contractABI.find(({ name }) => methodName === name); |
lndgalante
reviewed
Jun 4, 2020
Comment on lines
+105
to
+111
| const getIsArray = (value) => { | ||
| if (value.charAt(0) === '[' && value.charAt(value.length - 1) === ']' && !isNaN(value.substring(1, value.length - 1))) { | ||
| return parseInt(value.substring(1, value.length - 1), 10) | ||
| } else { | ||
| return false | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
Would prefer a RegExp for this scenario since it would be easier to understand and maintain
Suggested change
| const getIsArray = (value) => { | |
| if (value.charAt(0) === '[' && value.charAt(value.length - 1) === ']' && !isNaN(value.substring(1, value.length - 1))) { | |
| return parseInt(value.substring(1, value.length - 1), 10) | |
| } else { | |
| return false | |
| } | |
| } | |
| const getIsArray = (value) => { | |
| const [position] = value.match(/\d+/g) || []; | |
| const isPosition = !isNaN(position); | |
| return isPosition ? Number(position) : false; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🌟 Add support for overloaded functions